﻿using System;
using System.Collections.Generic;
using Ext.Net;

namespace BG.Web
{
    public class ExtHelper
    {
        #region Notification
        /// <summary>
        /// 返回Notification
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="content">内容</param>
        /// <returns></returns>
        public static Notification GetNotification(string title, string content)
        {
            return Notification.Show(new NotificationConfig
            {
                Title = title,
                HideDelay = 300,
                AlignCfg = new NotificationAlignConfig
                {
                    ElementAnchor = AnchorPoint.Top,
                    TargetAnchor = AnchorPoint.Top,
                    OffsetX = 0,
                    OffsetY = 10
                },
                ShowFx = new Frame { Color = "C3DAF9", Count = 1, Options = new FxConfig { Duration = 0 } },
                HideFx = new SwitchOff(),
                Html = content
            });
        }
        #endregion

        #region ErrorMsg
        /// <summary>
        /// 弹出ErrorMsg
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="message">内容</param>
        /// <param name="AnimEl">效果ID</param>
        public static void ErrorMsg(string title, string message, string AnimEl)
        {
            X.Msg.Show(new MessageBoxConfig
            {
                Title = title,
                Message = message,
                Width = 300,
                Buttons = MessageBox.Button.OK,
                AnimEl = AnimEl,
                Icon = MessageBox.Icon.ERROR
            });
        }
        #endregion

        #region GridCommand
        public static GridCommand.Config CreateGridCommand(string CommandName, Icon icon, string text, string tooltip)
        {
            GridCommand.Config config = new GridCommand.Config();
            config.CommandName = "Delete";
            config.Icon = Icon.Delete;
            config.Text = text;
            config.ToolTip.Text = tooltip;
            return config;
        }
        #endregion

        public static CommandColumn CreateCommandColumn(List<GridCommand> command)
        {
            CommandColumn cc = new CommandColumn();
            //cc.Hideable = Hideable;
            cc.Width = System.Web.UI.WebControls.Unit.Pixel(command.Count * 55);
            cc.Commands.AddRange(command as IEnumerable<GridCommand>);
            return cc;
        }

        public RadioGroup CreateRadioGroup(List<Radio> command, string fieldLabel, int id)
        {
            RadioGroup rg = new RadioGroup();
            rg.AnchorHorizontal = "98%"; rg.FieldLabel = fieldLabel; rg.ID = "rg" + id;
            rg.ColumnsNumber = command.Count;
            rg.Items.AddRange(command as IEnumerable<Radio>);
            return rg;
        }

        public Radio CreateRadio(string boxLabel, string id,bool isChecked)
        {
            return new Radio { ID = id, BoxLabel = boxLabel, Checked = isChecked };
        }
    }
}